package com.cqie.rbac.controller;


import com.cqie.rbac.bo.TermBo;
import com.cqie.rbac.entity.Course;
import com.cqie.rbac.entity.Term;
import com.cqie.rbac.entity.TestCourse;
import com.cqie.rbac.entity.TestTerm;
import com.cqie.rbac.mapper.TestCourseMapper;
import com.cqie.rbac.mapper.TestTermMapper;
import com.cqie.rbac.service.ITermService;
import com.cqie.rbac.util.MyPageHelper;
import com.cqie.rbac.util.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 学期表 前端控制器
 * </p>
 *
 * @author 单机吧
 * @since 2021-10-11
 */
@Api(tags ="学期管理")
@RestController
@RequestMapping("/term")
public class TermController {

    @Autowired
    private ITermService iTermService;
    @Autowired
    private TestTermMapper testTermMapper;

    @ApiOperation("获取学期列表信息")
    @GetMapping("/getTermList")
    public Result<PageInfo<Course>> GetTermList(TermBo bo){
        List<Term> list = iTermService.pageOfTerm(bo);
        return Result.ok().data(MyPageHelper.returnPage(list));
    }
    @ApiOperation("新增学期")
    @PostMapping("/insertTerm")
    public Result InsertTerm(TestTerm testTerm){
        testTermMapper.insert(testTerm);
        return Result.ok();
    }

    @ApiOperation("删除学期")
    @PostMapping("/deleteTerm")
    public Result DeleteTerm(Integer id){
        testTermMapper.deleteByPrimaryKey(id);
        return Result.ok();
    }

    @ApiOperation("修改学期")
    @PostMapping("/updateTerm")
    public Result UpdateTerm(TestTerm testTerm){
        testTermMapper.updateByPrimaryKeySelective(testTerm);
        return Result.ok();
    }

}
